Repository navigation
Load Always Encrypted keys asynchronously during parameter discovery - #5080
cheenamalhotra wants to merge 4 commits into
Conversation
Layer 3/5 of #4585. Defer CMK signature verification and CEK decryption from the describe-parameter-encryption parser so the async path awaits the async key-store utilities with the caller's token. Capture and reset the caller token across Reader/NonQuery/XML async setup and cleanup. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The tests use a provider that throws synchronously, leaving pending key-store I/O, successful metadata-cache publication, and cancellation followed by command reuse unverified.
1 open issue
What changed in this PR
This third layer of the Always Encrypted async integration connects parameter discovery to asynchronous key-store utilities without changing public APIs. Async query-metadata cache and enclave-package key loading remain deferred to later layers.
Changes:
- Shares describe-result parsing, defers signature verification and key decryption, and caches metadata only after key operations succeed.
- Captures caller cancellation tokens and improves cleanup for Reader, NonQuery, and XML async execution.
- Adds tests for provider dispatch, cancellation propagation, command reuse, and failed-setup cleanup.
| File | Description |
|---|---|
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlCommandTests.cs |
Adds cancellation and failed-setup token-cleanup tests. |
src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/AsyncKeyStoreProviderTests.cs |
Adds provider-dispatch, cancellation, and command-reuse integration tests. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Xml.cs |
Captures and clears XML execution tokens; handles failed-setup disposal. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Reader.cs |
Captures and clears reader execution tokens; refines failed-setup disposal. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.NonQuery.cs |
Captures and clears non-query execution tokens; handles failed-setup disposal. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Encryption.cs |
Defers key operations, selects sync or async utilities, and delays metadata caching until success. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs |
Adds and documents the saved async-execution cancellation token. |
Review effort: Balanced
Add a gated provider that holds async CEK decryption pending and then returns the real key. Cover successful completion after release and cancellation while the provider is pending, followed by command reuse. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Async Always Encrypted discovery changes parser/key-loading ordering and cancellation lifetimes, requiring human review and SQL Server/key-store validation because integration tests for success, cancellation, and command reuse were not run.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Async Always Encrypted discovery changes key-loading and cancellation lifetimes, requiring human validation because SQL Server/key-store integration tests for pending-provider completion, cancellation/reuse, and enclave signature verification have not run.
No open issues 🎉
Review effort: Balanced
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev/cheena/async-ae-crypto-utilities #5080 +/- ##
========================================================================
- Coverage 70.27% 70.15% -0.12%
========================================================================
Files 314 314
Lines 70018 70098 +80
========================================================================
- Hits 49202 49178 -24
- Misses 20816 20920 +104
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|

Description
Layer 3/5 split from #4585. Depends on #5079 (base branch).
CacheQueryMetadataIfNeeded). The parser documents its exception ordering and why keys load sequentially.ExecuteReaderAsync,ExecuteNonQueryAsyncandExecuteXmlReaderAsyncsave the caller's token, then clear it on cleanup and on failed setup. On failed setup, the async call context or the token registration is disposed.Integration is partial until later layers land:
Issues
Relates to #3672.
Testing
tests/UnitTests/Microsoft/Data/SqlClient/SqlCommandTests.cs, moved there from the source PR'sSqlCommandAsyncShould:End*Async_CanceledTask_ThrowsOperationCanceled(Reader, NonQuery, XML)*Async_FailedSetup_ClearsCancellationToken(Reader, NonQuery, XML; with and without a connection)ManualTests/AlwaysEncrypted/AsyncKeyStoreProviderTests.cs. They check that sync execution uses the sync provider API, that Reader/NonQuery/XML async execution uses the async API, and that the caller's token reaches the provider when it cancels.Validation (macOS):
dotnet test -f net10.0 -c Debug|Release --filter "FullyQualifiedName~Microsoft.Data.SqlClient.UnitTests.SqlCommandTests|FullyQualifiedName~SqlSecurityUtilityTests|FullyQualifiedName~SymmetricKeyCache": passed, 67/67, in both configurations.dotnet build -f net462for the driver, UnitTests and ManualTests: 0 errors.dotnet build -f net10.0for ManualTests: 0 errors.Guidelines
Please review the contribution guidelines before submitting a pull request: